package net.lab1024.sa.admin.module.business.expression.controller;

import net.lab1024.sa.admin.module.business.expression.domain.form.FuncExpressionAddForm;
import net.lab1024.sa.admin.module.business.expression.domain.form.FuncExpressionQueryForm;
import net.lab1024.sa.admin.module.business.expression.domain.form.FuncExpressionUpdateForm;
import net.lab1024.sa.admin.module.business.expression.domain.vo.FuncExpressionCalculateVO;
import net.lab1024.sa.admin.module.business.expression.domain.vo.FuncExpressionVO;
import net.lab1024.sa.admin.module.business.expression.service.FuncExpressionService;
import net.lab1024.sa.base.common.domain.ValidateList;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;

import java.util.List;

import static cn.dev33.satoken.SaManager.log;

/**
 * 函数表达式 Controller
 *
 * @Author zzx
 * @Date 2025-08-05 10:54:11
 * @Copyright zzx
 */

@RestController
@Tag(name = "函数表达式")
public class FuncExpressionController {

    @Resource
    private FuncExpressionService funcExpressionService;

    @Operation(summary = "计算 @author zzx")
    @PostMapping("/funcExpression/calculate")
    @SaCheckPermission("funcExpression:calculate")
    public ResponseDTO<Double> calculateData(@RequestBody @Valid FuncExpressionCalculateVO queryForm) {
        return ResponseDTO.ok(funcExpressionService.calculateData(queryForm));
    }

    @Operation(summary = "查询全部 @author zzx")
    @PostMapping("/funcExpression/queryAll")
    @SaCheckPermission("funcExpression:queryAll")
    public ResponseDTO<List<FuncExpressionCalculateVO>> queryAll(@RequestBody @Valid FuncExpressionQueryForm queryForm) {
        return ResponseDTO.ok(funcExpressionService.queryAll(queryForm));
    }

    @Operation(summary = "分页查询 @author zzx")
    @PostMapping("/funcExpression/queryPage")
    @SaCheckPermission("funcExpression:query")
    public ResponseDTO<PageResult<FuncExpressionVO>> queryPage(@RequestBody @Valid FuncExpressionQueryForm queryForm) {
        return ResponseDTO.ok(funcExpressionService.queryPage(queryForm));
    }

    @Operation(summary = "添加 @author zzx")
    @PostMapping("/funcExpression/add")
    @SaCheckPermission("funcExpression:add")
    public ResponseDTO<String> add(@RequestBody @Valid FuncExpressionAddForm addForm) {
        return funcExpressionService.add(addForm);
    }

    @Operation(summary = "更新 @author zzx")
    @PostMapping("/funcExpression/update")
    @SaCheckPermission("funcExpression:update")
    public ResponseDTO<String> update(@RequestBody @Valid FuncExpressionUpdateForm updateForm) {
        return funcExpressionService.update(updateForm);
    }

    @Operation(summary = "批量删除 @author zzx")
    @PostMapping("/funcExpression/batchDelete")
    @SaCheckPermission("funcExpression:delete")
    public ResponseDTO<String> batchDelete(@RequestBody ValidateList<Long> idList) {
        return funcExpressionService.batchDelete(idList);
    }

    @Operation(summary = "单个删除 @author zzx")
    @GetMapping("/funcExpression/delete/{funcId}")
    @SaCheckPermission("funcExpression:delete")
    public ResponseDTO<String> batchDelete(@PathVariable Long funcId) {
        return funcExpressionService.delete(funcId);
    }
}
